﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ConstellationShow.Function.DocData;

namespace ConstellationShow.Pages
{
    public partial class Collect : MyPage
    {
        public Collect()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Collect_Loaded);
        }

        void Collect_Loaded(object sender, RoutedEventArgs e)
        {
            object o = Com.GetSetting("cons");
            if (o != null)
            {
                List<Cons> lst = o as List<Cons>;
                foreach (Cons c in lst)
                {
                    foreach (var item in ContentPanel.Children)
                    {
                        if (item.GetType() == typeof(Button))
                        {
                            Button btn = item as Button;
                            if (btn.MinHeight == Convert.ToInt32(c.id))
                                btn.CommandParameter = "/Images/attention_02.png";
                        }
                    }
                }
            }
        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            object o = Com.GetSetting("cons");
            if (btn.CommandParameter.ToString() == "/Images/attention_01.png") //加入收藏
            {
                List<Cons> lst = new List<Cons>();
                if (o != null)
                {
                    if ((o as List<Cons>).Count >= 2)
                    {
                        MessageBox.Show("你最多关注2个哦！"); return;
                    }
                    lst = o as List<Cons>;
                }
                lst.Add(new Cons() { id = btn.MinHeight.ToString(), name = Info.ConvStr(btn.MinHeight.ToString()) });
                Com.SetSetting("cons", lst);
                btn.CommandParameter = "/Images/attention_02.png";
            }
            else {  //取消收藏
                if (o != null)
                {
                    List<Cons> lst = o as List<Cons>;
                    for (int i = 0; i < lst.Count; i++)
                        if (btn.MinHeight.ToString() == lst[i].id) lst.RemoveAt(i);
                    Com.SetSetting("cons", lst);
                }
                btn.CommandParameter = "/Images/attention_01.png";
            }
        }
    }
}